//-----------------------------------------------------------------------
// <copyright file="a_Users_SDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_Users_SDAOBase
    {
        #region Common methods
        public virtual a_Users_S Createa_Users_SFromReader(IDataReader reader)
        {
            a_Users_S item = new a_Users_S();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("UserID"))) item.UserID = (int)reader["UserID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CookieID"))) item.CookieID = (string)reader["CookieID"];
                if (!reader.IsDBNull(reader.GetOrdinal("Login_Email"))) item.Login_Email = (string)reader["Login_Email"];
                if (!reader.IsDBNull(reader.GetOrdinal("EmailConfirmed"))) item.EmailConfirmed = (bool)reader["EmailConfirmed"];
                if (!reader.IsDBNull(reader.GetOrdinal("Password"))) item.Password = (string)reader["Password"];
                if (!reader.IsDBNull(reader.GetOrdinal("Firstname"))) item.Firstname = (string)reader["Firstname"];
                if (!reader.IsDBNull(reader.GetOrdinal("Lastname"))) item.Lastname = (string)reader["Lastname"];
                if (!reader.IsDBNull(reader.GetOrdinal("Title"))) item.Title = (string)reader["Title"];
                if (!reader.IsDBNull(reader.GetOrdinal("Gender"))) item.Gender = (string)reader["Gender"];
                if (!reader.IsDBNull(reader.GetOrdinal("OrderPlacedToDate"))) item.OrderPlacedToDate = (int)reader["OrderPlacedToDate"];
                if (!reader.IsDBNull(reader.GetOrdinal("AmtSpentToDate"))) item.AmtSpentToDate = (decimal)reader["AmtSpentToDate"];
                if (!reader.IsDBNull(reader.GetOrdinal("CreditBalance"))) item.CreditBalance = (decimal)reader["CreditBalance"];
                if (!reader.IsDBNull(reader.GetOrdinal("PointBalance"))) item.PointBalance = (int)reader["PointBalance"];
                if (!reader.IsDBNull(reader.GetOrdinal("VisitCount"))) item.VisitCount = (int)reader["VisitCount"];
                if (!reader.IsDBNull(reader.GetOrdinal("Hits"))) item.Hits = (int)reader["Hits"];
                if (!reader.IsDBNull(reader.GetOrdinal("LastVisit"))) item.LastVisit = (DateTime)reader["LastVisit"];
                if (!reader.IsDBNull(reader.GetOrdinal("DateOpen"))) item.DateOpen = (DateTime)reader["DateOpen"];
                if (!reader.IsDBNull(reader.GetOrdinal("WLShareCode"))) item.WLShareCode = (string)reader["WLShareCode"];
                if (!reader.IsDBNull(reader.GetOrdinal("WLShareCount"))) item.WLShareCount = (int)reader["WLShareCount"];
                if (!reader.IsDBNull(reader.GetOrdinal("SurveySent"))) item.SurveySent = (bool)reader["SurveySent"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsDelete"))) item.IsDelete = (bool)reader["IsDelete"];
                if (!reader.IsDBNull(reader.GetOrdinal("IsActive"))) item.IsActive = (bool)reader["IsActive"];
                if (!reader.IsDBNull(reader.GetOrdinal("ShipReCalc"))) item.ShipReCalc = (bool)reader["ShipReCalc"];
                if (!reader.IsDBNull(reader.GetOrdinal("MainGroupID"))) item.MainGroupID = (int)reader["MainGroupID"];
                if (!reader.IsDBNull(reader.GetOrdinal("SubGroupID"))) item.SubGroupID = (int)reader["SubGroupID"];
                if (!reader.IsDBNull(reader.GetOrdinal("DomainID"))) item.DomainID = (int)reader["DomainID"];
                if (!reader.IsDBNull(reader.GetOrdinal("City"))) item.City = (string)reader["City"];
                if (!reader.IsDBNull(reader.GetOrdinal("Country"))) item.Country = (string)reader["Country"];
                if (!reader.IsDBNull(reader.GetOrdinal("Aboutme"))) item.Aboutme = (string)reader["Aboutme"];
                if (!reader.IsDBNull(reader.GetOrdinal("Nickname"))) item.Nickname = (string)reader["Nickname"];
                if (!reader.IsDBNull(reader.GetOrdinal("AucTransToDate"))) item.AucTransToDate = (int)reader["AucTransToDate"];
                if (!reader.IsDBNull(reader.GetOrdinal("State"))) item.State = (string)reader["State"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_Users_S methods
            
        public virtual void Createa_Users_S(a_Users_S a_Users_S)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Users_S_ins");
                
                database.AddInParameter(dbCommand, "@CookieID", DbType.AnsiString, a_Users_S.CookieID);
                database.AddInParameter(dbCommand, "@Login_Email", DbType.AnsiString, a_Users_S.Login_Email);
                database.AddInParameter(dbCommand, "@EmailConfirmed", DbType.Boolean, a_Users_S.EmailConfirmed);
                database.AddInParameter(dbCommand, "@Password", DbType.AnsiString, a_Users_S.Password);
                database.AddInParameter(dbCommand, "@Firstname", DbType.AnsiString, a_Users_S.Firstname);
                database.AddInParameter(dbCommand, "@Lastname", DbType.AnsiString, a_Users_S.Lastname);
                database.AddInParameter(dbCommand, "@Title", DbType.AnsiString, a_Users_S.Title);
                database.AddInParameter(dbCommand, "@Gender", DbType.AnsiStringFixedLength, a_Users_S.Gender);
                database.AddInParameter(dbCommand, "@OrderPlacedToDate", DbType.Int32, a_Users_S.OrderPlacedToDate);
                database.AddInParameter(dbCommand, "@AmtSpentToDate", DbType.Currency, a_Users_S.AmtSpentToDate);
                database.AddInParameter(dbCommand, "@CreditBalance", DbType.Currency, a_Users_S.CreditBalance);
                database.AddInParameter(dbCommand, "@PointBalance", DbType.Int32, a_Users_S.PointBalance);
                database.AddInParameter(dbCommand, "@VisitCount", DbType.Int32, a_Users_S.VisitCount);
                database.AddInParameter(dbCommand, "@Hits", DbType.Int32, a_Users_S.Hits);
                database.AddInParameter(dbCommand, "@LastVisit", DbType.DateTime, a_Users_S.LastVisit);
                database.AddInParameter(dbCommand, "@DateOpen", DbType.DateTime, a_Users_S.DateOpen);
                database.AddInParameter(dbCommand, "@WLShareCode", DbType.AnsiString, a_Users_S.WLShareCode);
                database.AddInParameter(dbCommand, "@WLShareCount", DbType.Int32, a_Users_S.WLShareCount);
                database.AddInParameter(dbCommand, "@SurveySent", DbType.Boolean, a_Users_S.SurveySent);
                database.AddInParameter(dbCommand, "@IsDelete", DbType.Boolean, a_Users_S.IsDelete);
                database.AddInParameter(dbCommand, "@IsActive", DbType.Boolean, a_Users_S.IsActive);
                database.AddInParameter(dbCommand, "@ShipReCalc", DbType.Boolean, a_Users_S.ShipReCalc);
                database.AddInParameter(dbCommand, "@MainGroupID", DbType.Int32, a_Users_S.MainGroupID);
                database.AddInParameter(dbCommand, "@SubGroupID", DbType.Int32, a_Users_S.SubGroupID);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_Users_S.DomainID);
                database.AddInParameter(dbCommand, "@City", DbType.AnsiString, a_Users_S.City);
                database.AddInParameter(dbCommand, "@Country", DbType.AnsiString, a_Users_S.Country);
                database.AddInParameter(dbCommand, "@Aboutme", DbType.AnsiString, a_Users_S.Aboutme);
                database.AddInParameter(dbCommand, "@Nickname", DbType.AnsiString, a_Users_S.Nickname);
                database.AddInParameter(dbCommand, "@AucTransToDate", DbType.Int32, a_Users_S.AucTransToDate);
                database.AddInParameter(dbCommand, "@State", DbType.AnsiString, a_Users_S.State);
                database.AddOutParameter(dbCommand, "@UserID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_Users_S.UserID = (int)database.GetParameterValue(dbCommand, "@UserID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_Users_S methods
        
        public virtual void Updatea_Users_S(a_Users_S a_Users_S)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Users_S_upd");            
                
                database.AddInParameter(dbCommand, "@UserID", DbType.Int32, a_Users_S.UserID);
                database.AddInParameter(dbCommand, "@CookieID", DbType.AnsiString, a_Users_S.CookieID);
                database.AddInParameter(dbCommand, "@Login_Email", DbType.AnsiString, a_Users_S.Login_Email);
                database.AddInParameter(dbCommand, "@EmailConfirmed", DbType.Boolean, a_Users_S.EmailConfirmed);
                database.AddInParameter(dbCommand, "@Password", DbType.AnsiString, a_Users_S.Password);
                database.AddInParameter(dbCommand, "@Firstname", DbType.AnsiString, a_Users_S.Firstname);
                database.AddInParameter(dbCommand, "@Lastname", DbType.AnsiString, a_Users_S.Lastname);
                database.AddInParameter(dbCommand, "@Title", DbType.AnsiString, a_Users_S.Title);
                database.AddInParameter(dbCommand, "@Gender", DbType.AnsiStringFixedLength, a_Users_S.Gender);
                database.AddInParameter(dbCommand, "@OrderPlacedToDate", DbType.Int32, a_Users_S.OrderPlacedToDate);
                database.AddInParameter(dbCommand, "@AmtSpentToDate", DbType.Currency, a_Users_S.AmtSpentToDate);
                database.AddInParameter(dbCommand, "@CreditBalance", DbType.Currency, a_Users_S.CreditBalance);
                database.AddInParameter(dbCommand, "@PointBalance", DbType.Int32, a_Users_S.PointBalance);
                database.AddInParameter(dbCommand, "@VisitCount", DbType.Int32, a_Users_S.VisitCount);
                database.AddInParameter(dbCommand, "@Hits", DbType.Int32, a_Users_S.Hits);
                database.AddInParameter(dbCommand, "@LastVisit", DbType.DateTime, a_Users_S.LastVisit);
                database.AddInParameter(dbCommand, "@DateOpen", DbType.DateTime, a_Users_S.DateOpen);
                database.AddInParameter(dbCommand, "@WLShareCode", DbType.AnsiString, a_Users_S.WLShareCode);
                database.AddInParameter(dbCommand, "@WLShareCount", DbType.Int32, a_Users_S.WLShareCount);
                database.AddInParameter(dbCommand, "@SurveySent", DbType.Boolean, a_Users_S.SurveySent);
                database.AddInParameter(dbCommand, "@IsDelete", DbType.Boolean, a_Users_S.IsDelete);
                database.AddInParameter(dbCommand, "@IsActive", DbType.Boolean, a_Users_S.IsActive);
                database.AddInParameter(dbCommand, "@ShipReCalc", DbType.Boolean, a_Users_S.ShipReCalc);
                database.AddInParameter(dbCommand, "@MainGroupID", DbType.Int32, a_Users_S.MainGroupID);
                database.AddInParameter(dbCommand, "@SubGroupID", DbType.Int32, a_Users_S.SubGroupID);
                database.AddInParameter(dbCommand, "@DomainID", DbType.Int32, a_Users_S.DomainID);
                database.AddInParameter(dbCommand, "@City", DbType.AnsiString, a_Users_S.City);
                database.AddInParameter(dbCommand, "@Country", DbType.AnsiString, a_Users_S.Country);
                database.AddInParameter(dbCommand, "@Aboutme", DbType.AnsiString, a_Users_S.Aboutme);
                database.AddInParameter(dbCommand, "@Nickname", DbType.AnsiString, a_Users_S.Nickname);
                database.AddInParameter(dbCommand, "@AucTransToDate", DbType.Int32, a_Users_S.AucTransToDate);
                database.AddInParameter(dbCommand, "@State", DbType.AnsiString, a_Users_S.State);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_Users_S methods
        public virtual void Deletea_Users_S(int userID)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Users_S_del");
                
                database.AddInParameter(dbCommand, "@UserID", DbType.Int32, userID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_Users_S methods
        
        public virtual a_Users_S Geta_Users_S(int userID)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Users_S_sel");
                
                database.AddInParameter(dbCommand, "@UserID", DbType.Int32, userID);
                
                a_Users_S a_Users_S =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_Users_S = Createa_Users_SFromReader(reader);
                        reader.Close();
                    }
                }
                return a_Users_S;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_Users_SList methods
        public virtual a_Users_SCollection Geta_Users_SList(a_Users_SColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_Users_S_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_Users_SCollection a_Users_SCollection = new a_Users_SCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_Users_S a_Users_S = Createa_Users_SFromReader(reader);
                        a_Users_SCollection.Add(a_Users_S);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_Users_SCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_Users_SCollection Geta_Users_SList(a_Users_SColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_Users_SList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion
    }
}